navigator | NN 2 IE 3 DOM n/a | ||||
The navigator object in many ways represents the browser application. As such, the browser is outside the scope of the document object model. Even so, the navigator object plays an important role in scripting, because it allows scripts to see what browser and browser version is running the script. In addition to several key properties that both Navigator and Internet Explorer have in common, each browser also extends the property listing of this object in ways that would generally benefit all browsers. | |||||
Object Model Reference
|
appCodeName | NN 2 IE 3 DOM n/a | ||
Read-only | |||
Reveals the code name of the browser. Both Navigator and Internet Explorer return Mozilla, which was the code name for an early version of Navigator (a combination of the early freeware name of the Mosaic browser and Godzilla). The Mozilla character is Netscape's corporate mascot, but both companies' browsers return this code name. | |||
Examplevar codeName = navigator.appCodeName | |||
Value Mozilla | |||
|
appMinorVersion | NN n/a IE 4 DOM n/a | ||
Read-only | |||
Reveals the value to the right of the decimal point in the entire version number. So-called bug-fix or patched versions, such as 4.03, are not reflected in IE's version numbering, so they return a value of 0. The exact release version is available by parsing the values of appVersion or userAgent. | |||
Examplevar subVer = navigator.appMinorVersion | |||
Value String version of the first digit to the right of the decimal of the primary version number. | |||
|
appName | NN 2 IE 3 DOM n/a | ||
Read-only | |||
Reveals the model name of the browser. | |||
Examplevar isNav = navigator.appName == "Netscape" | |||
Value String values. NN: Netscape; IE: Microsoft Internet Explorer | |||
|
appVersion | NN 2 IE 3 DOM n/a | ||
Read-only | |||
Reveals the version number of the browser, along with minimal operating system platform information (a subset of the information returned by userAgent). The first word of the value returned by Navigator includes the version number down to the x.xx level, whereas Internet Explorer goes only to the x.x level. In parentheses, both browsers include operating system information and (for Navigator) the browser's default language version. Sample returned values are as follows: Navigator: 4.04 [en] (Win95; I) 4.03 (Macintosh; I; PPC) Internet Explorer: 4.0 (compatible; MSIE 4.01; Windows 95) 4.0 (compatible; MSIE 4.0; Macintosh; I; PPC) You can use parseInt( ) on this value to determine whether a browser is of a particular generation, as shown in the following example. This extracts the integer value, which can be used in a math comparison operation to find out whether the browser is at a minimum needed version level for a script to run. | |||
Examplevar isVer4Min = parseInt(navigator.appVersion) >= 4 | |||
Value String values. | |||
|
browserLanguage | NN n/a IE 4 DOM n/a | ||
Read-only | |||
The default written language of the browser. The Navigator 4 equivalent is the navigator.language property. | |||
Examplevar browLangCode = navigator.browserLanguage | |||
Value Case-insensitive language code as a string. | |||
|
cpuClass | NN n/a IE 4 DOM n/a | ||
Read-only | |||
Returns a string reference of the CPU of the client computer. Common Intel microprocessors (including Pentium-class CPUs and Macintoshes running Windows emulators) return x86, while PowerPC Macintoshes return PPC. This value tells you only about the basic hardware class, not the operating system or specific CPU speed or model number. | |||
Exampleif (navigator.cpuClass == "PPC") { } | |||
Value String value. | |||
|
language | NN 4 IE n/a DOM n/a | ||
Read-only | |||
The written language for which the browser version was created. The language is specified in the ISO 639 language code scheme. Internet Explorer provides this information via the navigator.browserLanguage property. | |||
Examplevar mainLang = navigator.language | |||
Value Case-insensitive language code as a string. | |||
|
onLine | NN n/a IE 4 DOM n/a | ||
Read-only | |||
Whether the browser is set for online or offline browsing (in
Internet Explorer 4's | |||
Exampleif (navigator.onLine) { document.write("<APPLET ...>") ... } | |||
Value Boolean value: true | false. | |||
|
platform | NN 4 IE 4 DOM n/a | ||
Read-only | |||
Returns the name of the operating system or hardware platform of the browser. For Windows 95/NT, the value is Win32; for a Macintosh running a PowerPC CPU, the value is MacPPC. At least for the major platforms I've been able to test, Navigator and Internet Explorer agree on the returned values. Using this property to determine the baseline facilities of the client in a conditional expression can help the page optimize its output for the device. | |||
Exampleif (navigator.platform == "Win32") { } | |||
Value String. | |||
|
systemLanguage | NN n/a IE 4 DOM n/a | ||
Read-only | |||
The code for the default written language used by the operating system. If you have multi-lingual content available, you can use this property to insert content in specific languages. | |||
Exampleif (navigator.systemLanguage == "nl") { } | |||
Value Case-insensitive language code. | |||
|
userAgent | NN 2 IE 3 DOM n/a | ||
Read-only | |||
Information about the browser software, including version, operating system platform, and brand. This is the most complete set of information about the browser, whereas appVersion and appName properties provide subset data. Typical data for this property looks like the following: Mozilla/4.0 (compatible; MSIE 4.01; Windows 95) Do not rely on the length or position of any part of this data, as it may vary with browser, version, and proxy server used at the client end. Instead, use the indexOf( ) method to check for the presence of a desired string. | |||
Exampleif (navigator.userAgent.indexOf("MSIE") != -1) { var isIE = true } | |||
Value String. | |||
|
userLanguage | NN n/a IE 4 DOM n/a | ||
Read-only | |||
The default written language of the browser, based on the operating system user profile setting (if one exists). The property defaults to the browserLanguage property. | |||
Examplevar userLangCode = navigator.userLanguage | |||
Value Case-insensitive language code as a string. | |||
|
userProfile | NN n/a IE 4 DOM n/a | ||
Read-only | |||
The userProfile property is, itself, an object that lets scripts request permission to access personal information stored in the visitor's user profile (for Win32 versions of Internet Explorer 4). See the userProfile object. | |||
Examplenavigator.userProfile.addReadRequest("vcard.displayname") navigator.userProfile.doReadRequest("3", "MegaCorp Customer Service") var custName = navigator.userProfile.getAttribute("vcard.displayname") navigator.userProfile.clearRequest( ) if (custName) { ... } | |||
Value userProfile object reference. | |||
|
javaEnabled( ) | NN 3 IE 4 DOM n/a |
Returns whether Java is turned on in the browser. This property won't help you in a non-scriptable browser (or scriptable browser that doesn't support the property), but it does tell you whether the user has Java turned off in the browser preferences. | |
Returned Value Boolean value: true | false. | |
Parameters None. |
preference( ) | NN 4 IE n/a DOM n/a | ||||
preference(name[, value]) By way of signed scripts in Navigator 4, you can access a wide variety of user preferences settings. These include even the most detailed items, such as whether the user has elected to download images or whether style sheets are enabled. Most of these settings are intended for scripts used by network administrators to install and control the user settings of enterprisewide deployment of Navigator. Consult the Netscape developer web site for further information about these preferences settings (http://developer.netscape.com/library/documentation/deplymt/jsprefs.htm). | |||||
Returned Value Preference value in a variety of data types. | |||||
Parameters
|
taintEnabled( ) | NN 3 IE 4 DOM n/a |
Returns whether "data tainting" is turned on in the browser. This security mechanism was never fully implemented in Navigator, but the method that checks for it is still included in newer versions of Navigator for backward compatibility. Internet Explorer 4 also includes it for compatibility, even though it always returns false. | |
Returned Value Boolean value: true | false. | |
Parameters None. |